package com.bwie.conferenceroom.controller;

import com.bwie.common.domain.MeetingScheduling;
import com.bwie.common.domain.response.MeetingSchedulingRes;
import com.bwie.common.result.Result;
import com.bwie.conferenceroom.service.MeetingSchedulingService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Log4j2
public class MeetingSchedulingController {
    @Autowired
    private MeetingSchedulingService meetingSchedulingService;

    @Autowired
    private HttpServletRequest request;

    /**
     * 获取会议室预约列表
     * @return
     */
    @GetMapping("getMeetingSchedulingList")
    public Result getMeetingSchedulingList(){
        log.info("功能名称：获取会议室预约列表，请求url：{}，请求方式：{}",request.getRequestURI(),request.getMethod());
        List<MeetingSchedulingRes> list=meetingSchedulingService.getMeetingSchedulingList();
        Result<List<MeetingSchedulingRes>> result = Result.success(list);
        log.info("功能名称：获取会议室预约列表，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

    /**
     * 新增/修改预定会议室
     * @param meetingScheduling
     * @return
     */
    @PostMapping("saveOrUpdMeetingScheduling")
    public Result saveOrUpdMeetingScheduling(@RequestBody MeetingScheduling meetingScheduling){
        log.info("功能名称：新增/修改预定会议室，请求url：{}，请求方式：{}，请求参数：{}",request.getRequestURI(),request.getMethod(),meetingScheduling);
        meetingSchedulingService.saveOrUpdMeetingScheduling(meetingScheduling);
        Result<Object> result = Result.success();
        log.info("功能名称：新增/修改预定会议室，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

    /**
     * 删除预定会议室
     * @param id
     * @return
     */
    @DeleteMapping("delMeetingScheduling/{id}")
    public Result delMeetingScheduling(@PathVariable Integer id){
        log.info("功能名称：删除预定会议室，请求url：{}，请求方式：{}，请求参数：{}",request.getRequestURI(),request.getMethod(),id);
        meetingSchedulingService.delMeetingScheduling(id);
        Result<Object> result = Result.success();
        log.info("功能名称：删除预定会议室，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

}
